<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>promise.async&await</title>
</head>
<body>
<script type="text/javascript">
let time=0
let isOver=false
function showTime(){
	console.log(time)
	++time
	if(!isOver)setTimeout(showTime,990)
}
function getNumber(num,second){
	return new Promise((resolve, reject)=>{
		let n=parseInt(Math.random()*19)+num-9
		if(n<=num)setTimeout(resolve,second*1000,n)
		else reject({n:n,msg:'数值应该小于'+num})
	})
}
async function sum(){
	try{
		console.log('watit for n1')
		let n1=await getNumber(100,3)
		console.log('watit for n2')
		let n2=await getNumber(200,5)
		console.log(n1+' + '+n2+" = "+(n1+n2))
	}catch(e){
		console.log('error', e)
	}finally{
		isOver=true
	}
}
showTime()
sum()
</script>
</body>
</html>